//
//  BCOrderSecondCollectionViewCell.m
//  BangcaiBuy
//
//  Created by Liang Zhang on 16/6/15.
//  Copyright © 2016年 BCB. All rights reserved.
//

#import "BCOrderSecondCollectionViewCell.h"

@interface BCOrderSecondCollectionViewCell ()
@property (weak, nonatomic) IBOutlet UIButton *decButton;
@property (weak, nonatomic) IBOutlet UIButton *addButton;
@property (weak, nonatomic) IBOutlet UIButton *aLevel;
@property (weak, nonatomic) IBOutlet UIButton *bLevel;

@end

@implementation BCOrderSecondCollectionViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.decButton.layer.cornerRadius = self.decButton.frame.size.height/2;
    self.addButton.layer.cornerRadius = self.addButton.frame.size.height/2;
    self.aLevel.layer.cornerRadius = 5.f;
    self.aLevel.layer.borderWidth = 1.f;
    self.aLevel.layer.borderColor = [UIColor colorWithRed:71.f/255.f green:168.f/255.f blue:165.f/255.f alpha:1].CGColor;
    self.bLevel.layer.cornerRadius = 5.f;
    self.bLevel.layer.borderWidth = 1.f;
    self.bLevel.layer.borderColor = [UIColor colorWithRed:71.f/255.f green:168.f/255.f blue:165.f/255.f alpha:1].CGColor;
}

+ (instancetype)cellWithCollectionView:(UICollectionView *)collectionView {
    static NSString *ID = @"SecondCell";
    UINib *nib = [UINib nibWithNibName:@"BCOrderSecondCollectionViewCell" bundle: [NSBundle mainBundle]];
    [collectionView registerNib:nib forCellWithReuseIdentifier:ID];
    BCOrderSecondCollectionViewCell *cell = [[BCOrderSecondCollectionViewCell alloc] init];
    return cell;
}

- (IBAction)levelAction:(id)sender {
    UIButton *levelButton = (UIButton *)sender;
    if (1 == levelButton.tag) {
        self.aLevel.backgroundColor = [UIColor colorWithRed:71.f/255.f green:168.f/255.f blue:165.f/255.f alpha:1];
        [self.aLevel setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        self.bLevel.backgroundColor = [UIColor whiteColor];
        [self.bLevel setTitleColor:[UIColor colorWithRed:71.f/255.f green:168.f/255.f blue:165.f/255.f alpha:1] forState:UIControlStateNormal];
        self.level = 1;
    }
    else {
        self.bLevel.backgroundColor = [UIColor colorWithRed:71.f/255.f green:168.f/255.f blue:165.f/255.f alpha:1];
        [self.bLevel setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        self.aLevel.backgroundColor = [UIColor whiteColor];
        [self.aLevel setTitleColor:[UIColor colorWithRed:71.f/255.f green:168.f/255.f blue:165.f/255.f alpha:1] forState:UIControlStateNormal];
        self.level = 2;
    }
}

- (IBAction)decAction:(id)sender {
    if (self.count.text.integerValue > 1) {
        NSInteger count = self.count.text.integerValue - 1;
        self.count.text = [NSString stringWithFormat:@"%@",@(count)];
    }

}

- (IBAction)addAction:(id)sender {
    if (self.count.text.integerValue < 100) {
        NSInteger count = self.count.text.integerValue + 1;
        self.count.text = [NSString stringWithFormat:@"%@",@(count)];
    }
}

@end
